package com.yanqu.road.server.cmd.cookboy.process2;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cookboy.CookBoyModule;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyActivityMgr;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.S_CROSS_COOK_BOY2_FORBID_SPOON, desc = "")
public class CookBoy2ForbidSpoonCmd extends AbstractCommand {

	private int activityId;
	private List<Integer> spoonIdList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CookBoyProto.CookBoy2ForbidSpoonReqMsg reqMsg = CookBoyProto.CookBoy2ForbidSpoonReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		spoonIdList = reqMsg.getSpoonIdList();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = CookBoyActivityMgr.getOpenActivityInfo(activityId);
		if(activityInfo == null){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
			return;
		}
		player.getModule(CookBoyModule.class).setForbidSpoonIdList(activityId,spoonIdList);
		ret = CookBoyMgr.sendForbidSpoon(activityId,player.getUserId(),spoonIdList);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			CookBoyProto.CookBoy2ForbidSpoonRespMsg.Builder respMsg = CookBoyProto.CookBoy2ForbidSpoonRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_CROSS_COOK_BOY2_FORBID_SPOON, respMsg);
		}
	}
}
